package com.imedway.ihe.dd.util;

import com.imedway.ihe.dd.properties.ItiAddressProps;
import lombok.extern.slf4j.Slf4j;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * @author zhongyj <1126834403@qq.com><br/>
 * @date 2024/7/22
 */
@Slf4j
public class WebserviceUtil {

    /**
     * 创建WebService服务
     *
     * @param portTypeClass   PortType
     * @param serviceWsdl     wsdl地址
     * @param itiAddressProps 配置
     * @return Service
     */
    public static <T> T buildWebService(Class<T> portTypeClass, String serviceWsdl, ItiAddressProps itiAddressProps) {
        URL wsdlUrl = null;
        try {
            wsdlUrl = new URL(serviceWsdl);
        } catch (MalformedURLException e) {
            log.error("创建WebService服务失败");
        }
        QName serviceName = new QName(itiAddressProps.getServiceNamespaceUri(), itiAddressProps.getServiceLocalPart());
        Service service = Service.create(wsdlUrl, serviceName);
        return service.getPort(portTypeClass);
    }
}
